package com.csxy.lsh.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.csxy.lsh.R;
import com.csxy.lsh.entity.FlowerCategory;
import com.csxy.lsh.service.FlowerCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/flower/category")
public class FlowerCategoryController {
    @Autowired
    private FlowerCategoryService flowerCategoryService;

    // 查詢所有分類
    @GetMapping("/list")
    public R list() {
        List<FlowerCategory> list = flowerCategoryService.list(new QueryWrapper<FlowerCategory>().orderByAsc("gmt_create"));
        return R.ok().data("list", list);
    }

    // 根據ID查詢
    @GetMapping("/{id}")
    public R getById(@PathVariable String id) {
        FlowerCategory category = flowerCategoryService.getById(id);
        return R.ok().data("item", category);
    }

    // 新增
    @PostMapping("/add")
    public R add(@RequestBody FlowerCategory category) {
        flowerCategoryService.save(category);
        return R.ok();
    }

    // 更新
    @PostMapping("/update")
    public R update(@RequestBody FlowerCategory category) {
        flowerCategoryService.updateById(category);
        return R.ok();
    }

    // 刪除
    @PostMapping("/delete/{id}")
    public R delete(@PathVariable String id) {
        flowerCategoryService.removeById(id);
        return R.ok();
    }
} 